waitUntil {!LIB_mp_cutscene};
LIB_mp_cutscene = true;

{_x enableSimulation false;_x allowDamage false;} forEach allUnits;

1 fadeSound 0;
playSound "hint";

titleCut ["", "BLACK IN", 3];

_camera = "Camera" camCreate [0,0,0];
_camera cameraEffect ["INTERNAL","BACK"];
showCinemaBorder false;

;comment "Kavala";
_camera camPrepareTarget [-61954.22,82720.52,28933.02];
_camera camPreparePos [3486.05,12858.02,0.82];
_camera camPrepareFOV 0.700;
_camera camCommitPrepared 0;

/* who won? */
_winner = sideEnemy;
_winningscore = 0;
{
	_score = _x;
	if (_score > _winningscore && {_x == _score} count LIB_mp_scores == 1) then
	{
		_winner = LIB_mp_activesides select _forEachIndex;
		_winningscore = _score;
	};
} forEach LIB_mp_scores;

/* end text */
_endtext = switch (_winner) do
{
	case west : {"WEST WINS"};
	case east : {"EAST WINS"};
	case resistance : {"GUER WINS"};
	default {"DRAW"};
};

_endtext = _endtext + format ["\n\n%1: %2\n%3: %4\n%5: %6", "WEST", LIB_mp_scores select 0, "EAST", LIB_mp_scores select 1, "GUER", LIB_mp_scores select 2];
_endtime = if (LIB_mp_endtime > LIB_mp_timelimit and LIB_mp_timelimit>0) then {LIB_mp_timelimit;} else {floor LIB_mp_endtime;};
_zero = if (LIB_mp_endtime mod 60 < 10) then {0;} else {"";};
_endtext = _endtext + format ["\n\n%1:%2%3", abs (floor (_endtime * 0.01666666667)), _zero, _endtime mod 60];
2 cutText [_endtext, "PLAIN", 1.35];


/* music, tasks and appropriate debriefings according to side's result */
0 fadeMusic 0;
1 fadeMusic 0.9;

_end = "END2";
if (_winner != sideEnemy) then
{
	if (_winner == playerSide) then
	{
		_end = "END1";
		[] spawn {playMusic "bf42"};
	}
	else
	{
		_end = "LOSER";
		[] spawn {playMusic "bf42"};
	};
}
else
{
	[] spawn {playMusic "bf42"};
};

sleep 20;

_end call BIS_fnc_endMission;